package my.member;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import my.util.ConnUtil;



public class memberDao {
	public int insertproject(memberVo vo){
		
		int rst = 0;
		Connection conn=null;
		PreparedStatement ps=null;
		try{
			conn=ConnUtil.getConnection();
			String sql ="insert into jmboard_member(idx,userId,userPw,userName,userGrade,joinDate,email,email2,sent,tell,tell2,tell3,address,regdate) values("
					+ "null,?,?,?,?,null,?,?,?,?,?,?,?,sysdate())";
			ps=conn.prepareStatement(sql);
			ps.setString(1,vo.getuserId());
			ps.setString(2,vo.getuserPw());
			ps.setString(3,vo.getuserName());
			ps.setString(4,vo.getuserGrade());
			ps.setString(5,vo.getEmail());
			ps.setString(6,vo.getEmail2());
			ps.setString(7,vo.getSent());
			ps.setString(8,vo.getTell());
			ps.setString(9,vo.getTell2());
			ps.setString(10,vo.getTell3());
			ps.setString(11,vo.getAddress());
			
			rst=ps.executeUpdate();
			System.out.println(sql);
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			ConnUtil.close(ps, conn);
		}
		return rst;
	}
	public int userIdCheck(String userId){
		int rst =0;
		Connection conn=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		try{
			conn=ConnUtil.getConnection();
			String sql="select * from jmboard_member where userId=?";
			ps = conn.prepareStatement(sql);
			ps.setString(1, userId);
			rs = ps.executeQuery();
			if(rs.next()){
				rst=1;
			}
		}catch(Exception e){
			e.printStackTrace();
		
		}finally{
			ConnUtil.close(rs, ps, conn);
		}
		return rst;
		
	}

public int logincheck(String userId, String userPw){
		  int rst = 0;
		  Connection conn = null;
		  PreparedStatement ps = null;
		  ResultSet rs = null;
		  try{
		   conn = ConnUtil.getConnection();
		   String sql = "select * from jmboard_member where userId=?";
		   ps = conn.prepareStatement(sql);
		   ps.setString(1, userId);
		   rs = ps.executeQuery();
		   if(rs.next()){
		    String DBpass = rs.getString("userPw");
		     if((DBpass.trim()).equals((userPw.trim()))){
		      rst=2;  // �α��μ���
		     }else{
		      rst=1;   // ��й�ȣ Ʋ��
		     }
		  }  // ���̵� ����
		  }catch(Exception e){
		   e.printStackTrace();
		  }finally{
		   ConnUtil.close(rs, ps, conn);
		  }
		  return rst;
}
public int deletemember(String userId,String userPw){
	  int rst = 0;
	  Connection conn = null;
	  PreparedStatement ps = null;
	  ResultSet rs = null;
	  try{
	   conn = ConnUtil.getConnection();
	   String sql = "delete from jmboard_member where userId = ? and userPw = ?";
	   ps = conn.prepareStatement(sql);
	   ps.setString(1, userId);
	   ps.setString(2, userPw);
	   rst = ps.executeUpdate();
	  }catch(Exception e){
	   e.printStackTrace();
	  }finally{
	   ConnUtil.close(rs, ps, conn);
	  }
	  return rst;
	 }

public String findid(memberVo vo){
	  String userId = null;
	  Connection conn = null;
	  PreparedStatement ps = null;
	  ResultSet rs = null;
	  try{
	   conn = ConnUtil.getConnection();
	   String sql = "select userId from jmboard_member where userName=?  and tell=? and tell2=? and tell3=?	 ";
	   ps = conn.prepareStatement(sql);
	   ps.setString(1, vo.getuserName());
	   ps.setString(2, vo.getTell());
	   ps.setString(3, vo.getTell2());
	   ps.setString(4, vo.getTell3());

	   rs = ps.executeQuery();
	   while(rs.next()){
	    userId = rs.getString("userId");
	   }
	  }catch(Exception e){
	   e.printStackTrace();
	  }finally{
	   ConnUtil.close(rs, ps, conn);
	  }
	  return userId;
	 }
public String findpass(memberVo vo){
	  String userPw = null;
	  Connection conn = null;
	  PreparedStatement ps = null;
	  ResultSet rs = null;
	  try{
	   conn = ConnUtil.getConnection();
	   String sql = "select userPw from jmboard_member where userName=? and tell=? and tell2=? and tell3=? ";
	   ps = conn.prepareStatement(sql);
	   ps.setString(1, vo.getuserName());
	   ps.setString(2, vo.getTell());
	   ps.setString(3, vo.getTell2());
	   ps.setString(4, vo.getTell3());
	
	   rs = ps.executeQuery();
	   while(rs.next()){
		   userPw = rs.getString("userPw");
	   }
	  }catch(Exception e){
	   e.printStackTrace();
	  }finally{
	   ConnUtil.close(rs, ps, conn);
	  }
	  return userPw;
	 }



}
